import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';


class CustomText extends StatelessWidget {
  ///按钮文字
  final String text;

  ///行高
  final double? height;

  ///换行
  final bool? softWrap;

  ///文字样式
  final TextStyle? textStyle;

  ///字体颜色
  final Color? color;

  ///文字大小
  final double? fontSize;

  ///字重
  final FontWeight fontWeight;

  ///对齐方式
  final TextAlign? textAlign;

  ///文本基线
  final TextBaseline? textBaseline;

  ///文本溢出
  /// TextOverflow.clip: 截断并裁剪文本。
  /// TextOverflow.ellipsis: 用省略号表示溢出的文本。
  /// TextOverflow.fade: 使溢出的文本逐渐淡出。
  /// TextOverflow.visible: 显示全部文本，可能会超出边界。
  final TextOverflow? overflow;

  ///事件回调
  final VoidCallback? onPressed;

  const CustomText({
    super.key,
    this.height,
    this.softWrap,
    this.textStyle,
    this.color,
    this.onPressed,
    this.fontSize,
    this.textAlign,
    this.overflow,
    this.textBaseline,
    required this.text,
    this.fontWeight = FontWeight.normal,
  });

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onPressed,
      child: _buildChild(),
    );
  }

  /// 构建按钮内容
  Widget _buildChild() {
    var style = TextStyle(
      height: height,
      fontSize: fontSize ?? 16.sp,
      fontWeight: fontWeight,
      overflow: overflow,
      textBaseline: textBaseline,
      color: color ?? Colors.black,
    );
    return Text(text, softWrap: softWrap, textAlign: textAlign, style: textStyle ?? style);
  }
}
